package com.roadmap.repo.common;

import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;

import com.roadmap.common.BaseEntity;

public class RepoResultSet implements IRepoResultSet {
	protected Hashtable<String, BaseEntity> resultContainer;

	public RepoResultSet() {
		resultContainer = new Hashtable<String, BaseEntity>();
	}

	public void add(BaseEntity ent) {
		if (ent == null || ent.getId() == null)
			return;
		resultContainer.put(ent.getId(), ent);
	}

	public void delete(BaseEntity ent) {
		if (ent == null || ent.getId() == null)
			return;
		resultContainer.remove(ent.getId());
	}

	public BaseEntity get(String id) {
		if (id == null)
			return null;
		return resultContainer.get(id);
	}

	public List<BaseEntity> getAll() {
		List<BaseEntity> entities = new ArrayList<BaseEntity>();
		Iterator<BaseEntity> iter = resultContainer.values().iterator();
		while (iter.hasNext()) {
			entities.add(iter.next());
		}
		return entities;
	}
	
	public int size(){
		return resultContainer.size();
	}

	public void clear() {
		resultContainer.clear();
	}
}
